<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>第四版排产</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<style type="text/css">
		 .left-label {
		 	width: 120px !important
		 }
		 .layui-table th {
		    text-align: center;
		  }
	</style>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
    <div class="layui-inline">
    	<input class="layui-input" name="searchTime" id="searchTime" placeholder="请选择时间" style="display: inline; width: 80%">
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">  搜索</i></button>
</div>

<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
<table class="layui-hide" id="table2" lay-filter="table2"></table>

<div id="editDivID" hidden="hidden">
	<form class="layui-form" id="formID">
		<input type="hidden" id="id" name="id" lay-verify="id" >
		<input type="hidden" id="remark3" name="remark3" lay-verify="remark3" >
		<br>
		<label class="layui-form-label">审批意见</label>
		<input class="layui-input" type="text" id="remark4" name="remark4"  style="width:300px"><br>
		<button class="layui-btn layui-btn-blue" lay-submit lay-filter="subform" style="margin-left:140px">同意</button>
		<button class="layui-btn layui-btn-blue" lay-submit lay-filter="subform2" style="margin-left:50px">驳回</button>
	</form>
</div>	

<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="choose" id="test1"><i class="layui-icon layui-icon-upload">  导入</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="delete"><i class="layui-icon layui-icon-delete">批量删除</i></button>	
</div>
</script>

<script type="text/html" id="rowToolbar">
    {{#  if(d.remark3 == '未提交'){ }}
    <a class="layui-btn layui-btn-xs" lay-event="sub">提交</a>
    {{# }if(d.remark3 == '驳回') { }}
    <a class="layui-btn layui-btn-xs" lay-event="sub">重新提交</a>	
    {{# }if(d.remark3 == '审核中') { }}
     <a class="layui-btn layui-btn-xs" lay-event="edit">审批</a>
    {{#  } }}

</script>
<!-- 	{{#  if(d.remark3 == '未提交'){ }}
   <a class="layui-btn layui-btn-xs" lay-event="sub">提交</a>
	{{#  if( d.remark3 == '驳回' ){ }}
   <a class="layui-btn layui-btn-xs" lay-event="sub">提交</a>	
    {{# }if(d.remark3 == '审核中') { }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">审批</a>
    {{#  } }} -->
<!-- 	<a class="layui-btn layui-btn-xs" lay-event="sub">提交</a>
	<a class="layui-btn layui-btn-xs" lay-event="edit">审批</a> -->
 
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
 
<script type="text/javascript">

document.onkeydown = function(e){    
    var ev =document.all ? window.event : e;  
    if(ev.keyCode==13) { 
        $('.layui-btn').trigger("click");
		return false
    }  
  } 
	layui.use(['table','layer','upload','form','laydate'], function(){
		var table = layui.table;
		var layer = layui.layer;
		var laydate = layui.laydate;
	    var form = layui.form;
	    
		var $ = layui.jquery, active = {
			reload:function () {
				var searchTime = $("#searchTime").val();
				console.log(searchTime)
				table.reload('contenttable2',{
					method:'get',
					where:{"remark1":searchTime}
				});
			}
		}
		$('.layui-btn').on('click', function(){
	        var type = $(this).data('type');
	        active[type] ? active[type].call(this) : '';
	    });
		table.render({
		    elem: '#tableList'
		    ,url:'${pageContext.request.contextPath }/shedu/selectList.do'
		    ,toolbar: '#toolbar'
		    ,title: '排产单'
		    ,id :'contenttable'
		    ,limits:[10,20,30]
		    ,cols: [[
					  {type: 'checkbox', fixed: 'left'},
				      {field:'starttime', title:'开始时间'},
				      {field:'endtime', title:'结束时间'},
				      {field:'havetime', title:'已有日期'},
				      {field:'remark', title:'审批人'},
				      {field:'remark2', title:'审批时间'},
				      {field:'remark4', title:'审批意见'},
				      {field:'remark3', title:'审批状态'},
				      {fixed:'right', title:'操作', toolbar: '#rowToolbar', width:100}
				    ]],
		    page: true,
		});
		
		table.render({
		    elem: '#table2'
		    ,url:'${pageContext.request.contextPath }/shedu/selecDetailtList.do'
		    ,title: '排产单明细'
		    ,id :'contenttable2'
		    ,limits:[10,20,30]
		    ,cols: [[
				      {field:'remark1', title:'日期',rowspan: 2,align:'center',width:160},
				      {field:'', title:'当日工作量统计值',colspan: 10, align:'center'},
				      {field:'', title:'0960T',colspan: 10, align:'center'},
				      {field:'', title:'0980T',colspan: 10, align:'center'},
				      {field:'', title:'1080C',colspan: 10, align:'center'},
				      {field:'', title:'1060B',colspan: 10, align:'center'},
				      
				      {field:'', title:'一号线',colspan: 2, align:'center'},
				      {field:'', title:'二号线',colspan: 2, align:'center'},
				      {field:'', title:'三号线',colspan: 2, align:'center'},
				      {field:'', title:'四号线',colspan: 2, align:'center'},
				      {field:'', title:'五号线',colspan: 2, align:'center'},
				      {field:'', title:'六号线',colspan: 2, align:'center'}
				    ],
				    [ 
				      {field:'a1', title:'膜丝烘干',width:100},
				      {field:'a2', title:'膜丝缓存',width:100},
				      {field:'a3', title:'膜芯制作',width:100},
				      {field:'a4', title:'组件组装',width:100},
				      {field:'a5', title:'膜丝切割',width:100},
				      {field:'a6', title:'浇铸端盖安装',width:120},
				      {field:'a7', title:'组件吊装离心',width:120},
				      {field:'a8', title:'浇铸端盖拆卸',width:120},
				      {field:'a9', title:'组件欲固化缓存',width:130},
				      {field:'a10', title:'组件切割',width:100},
				      
				      {field:'b1', title:'膜丝烘干', edit: 'number', width:100},
				      {field:'b2', title:'膜丝缓存', edit: 'number', width:100},
				      {field:'b3', title:'膜芯制作', edit: 'number', width:100},
				      {field:'b4', title:'组件组装', edit: 'number', width:100},
				      {field:'b5', title:'膜丝切割', edit: 'number', width:100},
				      {field:'b6', title:'浇铸端盖安装', edit: 'number', width:120},
				      {field:'b7', title:'组件吊装离心', edit: 'number', width:120},
				      {field:'b8', title:'浇铸端盖拆卸', edit: 'number', width:120},
				      {field:'b9', title:'组件欲固化缓存', edit: 'number', width:130},
				      {field:'b10', title:'组件切割', edit: 'number', width:100},
				      
				      {field:'c1', title:'膜丝烘干', edit: 'number', width:100},
				      {field:'c2', title:'膜丝缓存', edit: 'number', width:100},
				      {field:'c3', title:'膜芯制作', edit: 'number', width:100},
				      {field:'c4', title:'组件组装', edit: 'number', width:100},
				      {field:'c5', title:'膜丝切割', edit: 'number', width:100},
				      {field:'c6', title:'浇铸端盖安装', edit: 'number', width:120},
				      {field:'c7', title:'组件吊装离心', edit: 'number', width:120},
				      {field:'c8', title:'浇铸端盖拆卸', edit: 'number', width:120},
				      {field:'c9', title:'组件欲固化缓存', edit: 'number', width:130},
				      {field:'c10', title:'组件切割', edit: 'number', width:100},
				      
				      {field:'d1', title:'膜丝烘干', edit: 'number', width:100},
				      {field:'d2', title:'膜丝缓存', edit: 'number', width:100},
				      {field:'d3', title:'膜芯制作', edit: 'number', width:100},
				      {field:'d4', title:'组件组装', edit: 'number', width:100},
				      {field:'d5', title:'膜丝切割', edit: 'number', width:100},
				      {field:'d6', title:'浇铸端盖安装', edit: 'number', width:120},
				      {field:'d7', title:'组件吊装离心', edit: 'number', width:120},
				      {field:'d8', title:'浇铸端盖拆卸', edit: 'number', width:120},
				      {field:'d9', title:'组件欲固化缓存', edit: 'number', width:130},
				      {field:'d10', title:'组件切割', edit: 'number', width:100},
				      
				      {field:'e1', title:'膜丝烘干', edit: 'number', width:100},
				      {field:'e2', title:'膜丝缓存', edit: 'number', width:100},
				      {field:'e3', title:'膜芯制作', edit: 'number', width:100},
				      {field:'e4', title:'组件组装', edit: 'number', width:100},
				      {field:'e5', title:'膜丝切割', edit: 'number', width:100},
				      {field:'e6', title:'浇铸端盖安装', edit: 'number', width:120},
				      {field:'e7', title:'组件吊装离心', edit: 'number', width:120},
				      {field:'e8', title:'浇铸端盖拆卸', edit: 'number', width:120},
				      {field:'e9', title:'组件欲固化缓存', edit: 'number', width:130},
				      {field:'e10', title:'组件切割', edit: 'number', width:100},
				      
				      
				      {field:'c09601', title:'0960', edit: 'number', width:100},
				      {field:'c09801', title:'0980', edit: 'number', width:100},
				      {field:'c09602', title:'0960', edit: 'number', width:100},
				      {field:'c09802', title:'0980', edit: 'number', width:100},
				      {field:'c09603', title:'0960', edit: 'number', width:100},
				      {field:'c09803', title:'0980', edit: 'number', width:100},
				      {field:'c09604', title:'0960', edit: 'number', width:100},
				      {field:'c09804', title:'0980', edit: 'number', width:100},
				      {field:'c10601', title:'1060', edit: 'number', width:100},
				      {field:'c10801', title:'1080', edit: 'number', width:100},
				      {field:'c10602', title:'1060', edit: 'number', width:100},
				      {field:'c10802', title:'1080', edit: 'number', width:100},
				    ]],
		    page: true,
		});
		
		
		
		//头工具栏事件
		table.on('toolbar(tableList)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id);
		    switch(obj.event){
		    	case 'delete':
		        	var data = checkStatus.data;
		        	var idArr = new Array();
		        	if(data.length==0){
		        		toastr.warning("请至少选择一条记录！");
		        	}else {
		        		
		        		for(var i=0;i<data.length;i++){
			        		if(data[i].remark3 == "同意" || data[i].remark3 == "审核中") {
			        			toastr.warning("对不起，审批过的不能删除");
			        			return;
			        		}
		        		}
		        		
		        		var ids = "";
			        	for(var i=0;i<data.length;i++){
		        			if(i != data.length-1) {
				        	 	ids +=data[i].id+",";
				        	 }else {
				        	 	ids +=data[i].id;
				        	 }
		        			
		        			layer.confirm('确定删除吗？', function(index){
						        $.ajax({
							    	type:'post',
							    	url:'${pageContext.request.contextPath }/shedu/delete.do',
							    	data:{"ids":ids},
							    	success:function(data){
							    		if(data > 0){
							    			toastr.success("删除成功！");
							    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
												window.location.reload();  
											},2000);
							    		}else{
							    			toastr.warning("删除失败！");
							    		}
							    	}
							    })
				        	})
			        	}
		        	}
		      	break;
		      	case 'select':
		      		console.log(obj)
		      	break;
		    };
		});
	  
		
		
		
		//监听行工具事件
		table.on('tool(tableList)', function(obj){
			var data = obj.data;
			console.log(obj)
			var id  = data.id;
			 if(obj.event === 'edit'){
				 
				 $.ajax({
					 async:false, 
					 type:'post',
			    	dataType: 'json',
			    	url:'/shedu/selectAuthority.do',
			    	success:function(data){
			    		if(data != 1) {
			    			toastr.warning("对不起，您没有权限！");
			    			return;
			    		}else {
			    			layer.open({
								  type: 1 		//Page层类型
								  ,area: ['500px', '200px'] //宽  高
								  ,title: '排产单审批'
								  ,shade: 0.6 	//遮罩透明度
								  ,maxmin: true //允许全屏最小化
								  ,anim: 1 		//0-6的动画形式，-1不开启
								  ,content:$("#editDivID")
								  ,success: function () {
									//回显表单数据
									$("#id").val(id);
								  }	
								  ,end: function(){
							  			$("#editDivID").hide();
							  		} 
							});
			    		}
			    	}
			    });
				 
			}else if(obj.event === 'sub') {
				layer.confirm('确定提交吗？', function(index){
				    var id = obj.data.id;
				    $.ajax({
				    	type:'post',
				    	url:'${pageContext.request.contextPath }/shedu/subShedu.do',
				    	data:{"id":id},
				    	success:function(data){
				    		if(data > 0){
				    			toastr.success("提交成功！");
				    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
									window.location.reload();  
								},2000);
				    		}else{
				    			toastr.warning("提交失败！");
				    		}
				    	}
				    })
				    layer.close(index);
				  });
			}
		});
		
		 //监听行单击事件（单击事件为：rowDouble）
		  table.on('row(tableList)', function(obj){
		    var data = obj.data;
			table.reload('contenttable2',{
				method:'get',
				where:{"remark2":data.id}
			});
		  });
		 
		 
		  table.on('edit(table2)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
              var data = obj.data;
		  
              var value = obj.value;//修改后的值
              var field = obj.field; //得到字段
              
              //修改操作
              $.ajax({
		    	type:'post',
		    	url:'${pageContext.request.contextPath }/shedu/editNum.do',
		    	data:""+field+"=" + value + "&id=" + data.id+"&remark3="+field,
		    	success:function(data){
		    		if(data > 0){
		    			toastr.success("修改成功！");
		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							window.location.reload();  
						},2000);
		    		}else{
		    			toastr.warning("修改失败！");
		    		}
		    	}
		    });
              
          });
		 
		
		/**
	     * 审批（同意）
	     */
	    form.on('submit(subform)', function (data) {
	    	
	    	$("#remark3").val("审批通过");
	    	$.ajax({
				url : '${pageContext.request.contextPath}/shedu/edit.do',
				data: data.field,
				data : new FormData($('#formID')[0]),
				cache : false,
				type : "post",
				dataType : "json",
				processData : false,
				contentType : false,
				}).done(
					function(res) {
						if (res == 1) {
							toastr.success('审批完成！');
							setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
								window.location.reload();  
							},2000);
						}
						$("#reset").click();
					}
				).fail(
					function(res) {
						toastr.error('审批失败！');
					}
				)
				return false;
	    	});
	    
		
	    /**
	     * 审批（驳回）
	     */
	    form.on('submit(subform2)', function (data) {
	    	$("#remark3").val("已驳回");
	    	$.ajax({
				url : '${pageContext.request.contextPath}/shedu/edit.do',
				data: data.field,
				data : new FormData($('#formID')[0]),
				cache : false,
				type : "post",
				dataType : "json",
				processData : false,
				contentType : false,
				}).done(
					function(res) {
						if (res == 1) {
							toastr.success('已驳回!');
							setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
								window.location.reload();  
							},2000);
						}
						$("#reset").click();
					}
				).fail(
					function(res) {
						toastr.error('驳回失败！');
					}
				)
				return false;
	    });
	    
    
    
  //时间格式化
    laydate.render({
      elem: '#searchTime',
      format: 'yyyy-MM-dd'
    });
    laydate.render({
      elem: '#datatime',
      format: 'yyyy-MM-dd'
    });
    laydate.render({
      elem: '#datatime2',
      format: 'yyyy-MM-dd'
    });
});

toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>

<script>
layui.use(['element','upload'], function(){
  var $ = layui.jquery
  ,element = layui.element;
  upload = layui.upload;
  
  //指定允许上传的文件类型
  upload.render({
    elem: '#test1'
    ,url: '${pageContext.request.contextPath }/shedu/uploadPlan.do'
    ,accept: 'file' //普通文件
    ,method: 'POST'
   	,field: "file" 
 	,before: function(obj){
 		layer.load();
    }
  ,done: function(res){//上传完毕回调
      layer.closeAll('loading');
      
      if (res >0) {
			toastr.success('导入成功！');
			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
				window.location.reload();  
			},2000);
		}else {
			layer.closeAll('loading');
		      toastr.error('导入失败！');
		}
  }
  ,error: function(){//请求异常回调
      layer.closeAll('loading');
      toastr.error('网络异常，请稍后重试！');
  }
  });
});
</script>

</body>
</html>